/*!
 * FileName: luogu-1546.cpp
 * This Problem is on luogu. The ID of the problem is 1546. 
 * Copyright(c) 2019 Shu_Yu_Mo
 * MIT Licensed
 * Luogu: https://www.luogu.org/space/show?uid=44615
 * Github: https://github.com/oldsuold/
 * Gitee: https://gitee.com/Shu_Yu_Mo/
 * These words were created by an amazing tool written by Shu_Yu_Mo.
 */
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstring>
#include<iostream>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
#define inf 0x7fffffff
using namespace std;
const int _ = 233;
inline int read()
{
    char c = getchar(); int sign = 1; int x = 0;
    while(c > '9' || c < '0') { if(c=='-')sign = -1; c = getchar(); } 
    while(c <= '9' && c >= '0') { x *= 10; x += c - '0'; c = getchar(); }
    return x * sign;
}
int Min[_];
int g[_][_];
bool vis[_];
int n;
int tmp[_];
int ansA[_];
int ansB[_];
int tot = 0;
int main()
{
	memset(Min, 0x7f, sizeof(Min));
	memset(vis, false, sizeof(vis));
	n = read();
	for(register int i = 1;i <= n;i++)
		for(register int j = 1;j <= n;j++)
			g[i][j] = read();
	Min[1] = 0;
	for(register int i = 1;i <= n;i++)
	{
		int k = 0;
		for(register int j = 1;j <= n;j++)
			if(!vis[j] && Min[k] > Min[j])
				k = j;
//		printf("find %d\n", k);
		vis[k] = true;
//		if(tmp[k] != -1)
//		{
//			ansA[++tot] = tmp[k];
//			ansB[tot] = k; 
//		}
		for(register int j = 1;j <= n;j++)
			if(!vis[j] && Min[j] > g[k][j])
				Min[j] = g[k][j];//, tmp[j] = (g[k][j] == 0 ? -1 : k );
	}
	int ans = 0;
//	printf("%d\n", tot - 1);
//	for(register int i = 2;i <= tot;i++)
//		printf("%d %d\n", min(ansA[i], ansB[i]), max(ansA[i], ansB[i])), ans += Min[ansB[i]];
	for(register int i = 1;i <= n;i++)
		ans += Min[i];
	printf("%d", ans);
    return 0;
}
